﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net.Mail;
using System.Text;
using TSqlServer;

public partial class my_pubnews_mailto : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string mailtitle = Request["articletitle"].ToString();
        string sSql = "select email from t_linkman where companyabb in ('汽车画报','动感驾驭','汽车在线')";
        //string sSql = "select email from t_linkman where companyabb in ('汽车在线')";
        //string sSql = "select email from t_linkman where linkman='王剑锋' or linkman='刘玉升'";
        TSqlDBReader oList = new TSqlDBReader(sSql);
        while (oList.FDataReader.Read())
        {
            string emailaddr = oList.FDataReader.GetValue(0).ToString();
            senmail(mailtitle, emailaddr);
        }
        oList.Free();
        Response.End();
    }

    private bool senmail(string mailtitle,string toemailaddr)
    {
        bool result = true;
        
        //string easrcrmindex="http://172.16.21.162/easycrm/";
        string easrcrmindex = TCommon.wwwurl;
        
        SmtpClient oSmtp = new SmtpClient("smtp.cnap.com.cn");
        oSmtp.Credentials = new System.Net.NetworkCredential("admin@cnap.com.cn", "mala990707");

        MailAddress fromemail = new MailAddress("admin@cnap.com.cn", "EasyCRM管理员");

        MailAddress toemail = new MailAddress(toemailaddr);

        MailMessage oMail = new MailMessage(fromemail, toemail);
        oMail.Subject = mailtitle;
        oMail.SubjectEncoding = Encoding.GetEncoding("GB2312");
        oMail.Priority = MailPriority.Normal;
        oMail.IsBodyHtml = true;
        oMail.Body = "<a href=\"" + easrcrmindex + "\">" + mailtitle + "</a>";
        oMail.BodyEncoding = Encoding.GetEncoding("GB2312");
        try
        {
            oSmtp.Send(oMail);
        }
        catch (Exception e)
        {
            result = false;
        };
        
        return result;
    }
}
